'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../../common/component');
var utils_1 = require('../../common/utils');
component_1.VantComponent({
  classes: ['title-class'],
  props: {
    title: String,
    fixed: {
      type: Boolean,
      observer: 'setHeight',
    },
    placeholder: {
      type: Boolean,
      observer: 'setHeight',
    },
    leftText: String,
    rightText: String,
    customStyle: String,
    capsuleStyle: String,  //左边按钮
    leftArrow: Boolean,
    border: {
      type: Boolean,
      value: true,
    },
    zIndex: {
      type: Number,
      value: 10,
    },
    noredirect: {
      type: Boolean,
      value: false,
    },
    tittlealign: {
      type: String,
      value: "center",  //left,center
    },
    txtcss: {
      type: String,
      value: "",   
    },
    
    mode: {
      type: String,
      value: "auto",  //auto home goback
    },
    safeAreaInsetTop: {
      type: Boolean,
      value: true,
    },
    backlink: {
      type: [Object,String],
      value: '',
    }
  },
  data: {
    statusBarHeight: 0,
    height: 44,
    baseStyle: '',
    plen: 0,
    capsuleData: { count: 0, showhome: false, showblack: false }
  },

  created: function () {
    var statusBarHeight = utils_1.getSystemInfoSync().statusBarHeight;
    var _a = this.data,
      safeAreaInsetTop = _a.safeAreaInsetTop,
      zIndex = _a.zIndex;
    var paddingTop = safeAreaInsetTop ? statusBarHeight : 0;
    var baseStyle =
      'z-index: ' + zIndex + ';padding-top: ' + paddingTop + 'px;';
    let capsule = wx.getMenuButtonBoundingClientRect();

  
  
    var titlheigth= (capsule.top -statusBarHeight) * 2  + capsule.height
     
    var titlecss = this.data.txtcss+";height:" + capsule.height + "px;line-height:" + capsule.height + "px;";
  if (this.data.tittlealign == "left") {
    titlecss += "text-align:left";
  }
    // if (this.data.tittlealign == "left") {
    //   titlecss += "left:0px;position:statice;margin-top:" + (capsule.top - paddingTop) * 1.5 + "px;";

    // }
    // else {
    //   titlecss += "top:" + (capsule.top - paddingTop) * 1.5 + "px;";
    // }
    this.setData({
      statusBarHeight: statusBarHeight,
      height: titlheigth + statusBarHeight,
      titlheigth:titlheigth,
      baseStyle: baseStyle,
      titlecss: titlecss
    });
  },
  mounted: function () {
    this.calculatecapsule()
    this.setHeight();
  },
  ready() {
    //backlink  
  },
  methods: {
    diynavigateTo: function (ev) {

      var dataset= ev.currentTarget.dataset
      var item = dataset.item; 
      if(!item)
      {
        return ;
      }
 
       
     
      app.xc_sys_config.router.diynavigateTo(item)

    },
    _navigateTo: function (url, model, para) {
    
      var urlpara = [];
      if (para) {
        var attrpara = para.split(",");
        for (var a in attrpara) {
          urlpara.push(attrpara[a] + "=" + model[attrpara[a]])
        }
        if (url.indexOf("?") < 0) {
          url = url + "?";
        }
        else {
          url = url + "&";
        }
        url += urlpara.join("&")
      }
      var app = getApp();
      app.xc_sys_config.router.navigateTo(url)
    },
    goback(e) {

  


    var   backlinktype=typeof (this.data.backlink)
      if(backlinktype== "object" &&(this.data.backlink["cid"])){
        var app = getApp()
        app.xc_sys_config.router.diynavigateTo(this.data.backlink)
      } 
      else if (backlinktype=='string' && this.data.backlink) {
     
        wx.redirectTo({
          url: this.data.backlink,
        })
      }
      else {
        if (this.data.noredirect) {
          this.onClickLeft()
        }
        else {
          wx.navigateBack({
            delta: 1
          })
        }
      }

    },
    gohome() {
      var app = getApp();

      wx.reLaunch({ url: app.globalData.configdata["basic"]["homeurl"] });
    },
    calculatecapsule: function () {

      var $_pages = getCurrentPages()
      var plen = $_pages.length;
      this.setData({ plen: plen })

      var capsuleData = { count: 0, showhome: false, showblack: false }
      if (this.data.mode == "auto") {
        if (this.data.plen > 1) {


          capsuleData.count++;
          capsuleData.showblack = true;
        }
        capsuleData.count++;
        capsuleData.showhome = true;
      } else if (this.data.mode == "home") {
        capsuleData.count++;
        capsuleData.showhome = true;
      } else if (this.data.mode == "black") {
        capsuleData.count++;
        capsuleData.showhome = true;
      }
      this.setData({ capsuleData: capsuleData })

    },
    onClickLeft: function () {
      this.$emit('click-left');
    },
    onClickRight: function () {
      this.$emit('click-right');
    },
    setHeight: function () {
      var _this = this;
      if (!this.data.fixed || !this.data.placeholder) {
        return;
      }
      wx.nextTick(function () {
        _this.getRect('.van-nav-bar').then(function (res) {
          if (res.height !== 0) {
            _this.setData({ height: res.height });
          }

        });
      });
    },
  },
});
